package petertel.pbx.controller;

import javax.servlet.http.HttpSession;

public abstract class BaseController<T>  {
	
	protected void serialize(HttpSession sess, T object) {
		String type = this.getClass().getName();
		sess.setAttribute("type", type);
		sess.setAttribute("data", object);
	}

	protected T deserialize(HttpSession sess) {
		String expectedType = this.getClass().getName();
		String type = (String) sess.getAttribute("type");
		if (!expectedType.equals(type)) {
			return null;
		}
		T object = (T) sess.getAttribute("data");
		return object;
	}

}
